package com.sx.jys.ui.act

import android.os.Bundle
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener
import com.sos.widget.view.refresh.finishLoad
import com.sx.jys.app.framework.BaseActivity
import com.sx.jys.databinding.ActCkDetailBinding
import com.sx.jys.ui.adapter.ItemDetailAdapter
import com.sx.jys.ui.vm.CkDetailVm

class CkDetailAct : BaseActivity<CkDetailVm, ActCkDetailBinding>() {
    var page = 1
    override fun initView(savedInstanceState: Bundle?) {
        getImmersionBar().titleBar(titleBar).init()
        mDatabind.myRefresh.setOnRefreshLoadMoreListener(object : OnRefreshLoadMoreListener {
            override fun onRefresh(refreshLayout: RefreshLayout) {
                refreshLayout.finishRefresh(2500)
                page = 1
                mViewModel.reqDetailList(page)
            }

            override fun onLoadMore(refreshLayout: RefreshLayout) {
                refreshLayout.finishLoadMore(2500)
                page += 1
                mViewModel.reqDetailList(page)
            }
        })
    }

    override fun initData() {
        mDatabind.vm = mViewModel
        mDatabind.adapter = ItemDetailAdapter(this)
        mViewModel.status= intent.getStringExtra("status").orEmpty()
        mViewModel.code= intent.getStringExtra("code").orEmpty()
        mViewModel.openTime= intent.getStringExtra("openTime").orEmpty()
        mViewModel.reqDetailList(page)
    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.uiState.refreshEvent.observe(this) {
            mDatabind.myRefresh.finishRefresh()
        }
        mViewModel.uiState.loadMoreEvent.observe(this) {
            mDatabind.myRefresh.finishLoad(it)
        }
    }
}